/*
 *  CEDictMaker.h
 *  LID Library
 *
 *  Created by Alexander Trutchenko on 11/01/12.
 *  Copyright 2012 League of Independent Developers. All rights reserved.
 *
 */


#ifndef __CE_DictMaker_h__
#define __CE_DictMaker_h__


#include "cocos2d.h"

#include <stack>

namespace cocosext {

typedef enum 
{
    CE_SAX_NONE = 0,
    CE_SAX_KEY,
    CE_SAX_DICT,
    CE_SAX_INT,
    CE_SAX_REAL,
    CE_SAX_STRING,
    CE_SAX_ARRAY
} ceSAXState;

class CEDictMaker : public cocos2d::CCSAXDelegator
{
public:
    cocos2d::CCDictionary<std::string, cocos2d::CCObject*> *m_pRootDict;
    cocos2d::CCDictionary<std::string, cocos2d::CCObject*> *m_pCurDict;
    std::stack<cocos2d::CCDictionary<std::string, cocos2d::CCObject*>*> m_tDictStack;
    std::string m_sCurKey;///< parsed key
    ceSAXState m_tState;
    cocos2d::CCMutableArray<cocos2d::CCObject*> *m_pArray;

    std::stack<cocos2d::CCMutableArray<cocos2d::CCObject*>*> m_tArrayStack;
    std::stack<ceSAXState>  m_tStateStack;

public:
    CEDictMaker(): m_pRootDict(NULL),
                     m_pCurDict(NULL),
                     m_tState(CE_SAX_NONE),
                     m_pArray(NULL) {;}

    ~CEDictMaker() {;}

    cocos2d::CCDictionary<std::string, cocos2d::CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
    void startElement(void *ctx, const char *name, const char **atts);
    void endElement(void *ctx, const char *name);
    void textHandler(void *ctx, const char *ch, int len);
};


} // cocosext

#endif //__CE_DictMaker_h__
